package cur.nature.component.nacos.property;

import lombok.Data;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.util.List;

@Configuration
@ConfigurationProperties(prefix = "microservice")
@Data
@ConditionalOnProperty( value = {"cur.component.nacos.enable"})
public class MicroPropertyConfig {

    private List<MicroPropertyBean> beanList; // 微服务列表

    public MicroPropertyBean getProperty(final String serviceName) {
        if (beanList == null || beanList.isEmpty()) { return null; }
        for (MicroPropertyBean bean : beanList) {
            if (bean.getServiceName().equals(serviceName)) { return bean; }
        }
        return null;
    }
}
